Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
@turf/distance
Advanced tools
@turf/distance is a module of the Turf.js library, which provides geospatial analysis tools. This specific module calculates the distance between two geographical points using various measurement units such as miles, kilometers, and degrees.
Calculate Distance in Kilometers
This feature calculates the distance between two geographical points in kilometers. The 'from' and 'to' variables represent the coordinates of the two points.
const turf = require('@turf/distance');
const from = [0, 0];
const to = [1, 1];
const options = { units: 'kilometers' };
const distance = turf(from, to, options);
console.log(distance);
Calculate Distance in Miles
This feature calculates the distance between two geographical points in miles. The 'from' and 'to' variables represent the coordinates of the two points.
const turf = require('@turf/distance');
const from = [0, 0];
const to = [1, 1];
const options = { units: 'miles' };
const distance = turf(from, to, options);
console.log(distance);
Calculate Distance in Degrees
This feature calculates the distance between two geographical points in degrees. The 'from' and 'to' variables represent the coordinates of the two points.
const turf = require('@turf/distance');
const from = [0, 0];
const to = [1, 1];
const options = { units: 'degrees' };
const distance = turf(from, to, options);
console.log(distance);
Geolib is a library to provide basic geospatial operations like distance calculation, area calculation, and more. It offers similar functionalities to @turf/distance but also includes additional features like finding the center of a cluster of points.
Geodesy is a library for geodesic calculations, including distance and bearing between points, and conversions between different coordinate systems. It provides more advanced geospatial calculations compared to @turf/distance.
Spherical Geometry is a library for performing spherical geometry calculations, including distance and area calculations on the surface of a sphere. It is similar to @turf/distance but focuses on spherical geometry.
Calculates the distance between two coordinates in degrees, radians, miles, or kilometers. This uses the Haversine formula to account for global curvature.
from
Coord origin coordinate
to
Coord destination coordinate
options
Object Optional parameters (optional, default {}
)
options.units
string can be degrees, radians, miles, or kilometers (optional, default 'kilometers'
)var from = turf.point([-75.343, 39.984]);
var to = turf.point([-75.534, 39.123]);
var options = {units: 'miles'};
var distance = turf.distance(from, to, options);
//addToMap
var addToMap = [from, to];
from.properties.distance = distance;
to.properties.distance = distance;
Returns number distance between the two coordinates
This module is part of the Turfjs project, an open source module collection dedicated to geographic algorithms. It is maintained in the Turfjs/turf repository, where you can create PRs and issues.
Install this single module individually:
$ npm install @turf/distance
Or install the all-encompassing @turf/turf module that includes all modules as functions:
$ npm install @turf/turf
FAQs
turf distance module
The npm package @turf/distance receives a total of 1,325,159 weekly downloads. As such, @turf/distance popularity was classified as popular.
We found that @turf/distance demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.